1 按年龄从大到小排序
select * from stu order by age desc;

2 关键字顺序
select order by  where   limit  from

select 
from
where 
order by 
limit 

3 查看 #年龄最小的 #李姓  #男同学
SELECT * FROM stu 
WHERE left(sname,1)='李' AND sex=1 
ORDER BY age asc 
LIMIT 1;

4 随机排列
select * from stu order by rand() ;

5 #随机 #选一个 #大于20岁 #的女同学
select * from stu where sex=2 and age>20 
order by rand() limit 1;

6 使用in查找年龄是 19,20,35的女学生
select * from stu where age in(19,20,35); 

7 查找姓名包含“小”字  且年龄最小的  男同学 
 select * from stu where sname like '%小%' and sex=1
 order by age asc limit 1;

8 使用between查找年龄在20~35岁间，年龄最小的 姓王的 女生
select * from stu where age between 20 and 35
and sname like '王%'  and sex=2
order by age asc limit 1; 

9 将所有20岁以下 的女生 年龄减5岁
update stu set age=age-5 where age<20 and sex=2;

10 将年龄第2小的男生删除
select id from stu order by age asc limit 1,1;
delete from stu where id=5 and sex=1;

delete from stu where id in(select * from(select id from stu where sex =1 order by age asc limit 1,1)as c);


11 删除年龄在20~30岁的李姓同学 
delete from stu 
where age between 20 and 30 
and sname like '李%';


12 将所有男生名子前加"后盾_"
update stu set sname=concat('后盾_',sname) where sex=1;




































